<template>
  <div>
    <el-dialog
      width="30%"
      :visible.sync="visible"
      title="修改个人信息"
      :close-on-click-modal="false"
    >
      <el-form>
        <el-form-item label="用户名" label-width="100px">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="个人介绍" label-width="100px" prop="reNewPassword">
          <el-input
            type="textarea"
            v-model="form.introduction"
            @keyup.enter.native="onSubmit"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="onSubmit">修改</el-button>
          <el-button @click="updateInfoClosed">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
<script>
import * as api from "@/api/user.js";
import { mapGetters } from "vuex";
import store from "@/store";

export default {
  computed: {
    ...mapGetters(["name"]),
    ...mapGetters(["introduction"]),
  },
  data() {
    return {
      visible: false,
      form: {
        username: "",
        name: "",
        introduction: "",
      },
    };
  },

  methods: {
    onSubmit() {
      api
        .updateInfo(this.form.username, this.form.name, this.form.introduction)
        .then((response) => {
          this.$message.success(response.msg);
          this.updateInfoClosed();
          this.$store.commit("user/SET_INTRODUCTION", this.form.introduction);
          this.$store.commit("user/SET_NAME", this.form.name);

          // console.log(this.$store.dispatch('user/getInfo'));
          // console.log(this.introduction);
        });
    },
    updateInfoClosed() {
      this.$emit("collBackInfo");
    },
    updateInfoClosed() {
      this.visible = false;
    },
    open(username, name, introduction) {
      this.form.username = username;
      this.form.name = name;
      this.form.introduction = introduction;
      this.visible = true;
    },
  },
};
</script>
